﻿using System;
using Pyxis.FluentSelenium.SimpleWebApp.Shopping.Domain;

namespace Pyxis.FluentSelenium.SimpleWebApp.Shopping
{
    public partial class SearchResults : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var searchText = Session["searchText"] ?? "";
            Search(searchText.ToString());
        }

        private void Search(string searchText)
        {
            var searchResults = ProductCatalog.Search(searchText);
            if (searchResults.Count == 1)
            {
                searchResultsSummary.Text = "1 match found";
            }
            else
            {
                searchResultsSummary.Text = string.Format("{0} matches found", searchResults.Count);
            }

            Repeater1.DataSource = searchResults;
            Repeater1.DataBind();
        }
    }
}